package com.accp.dao.impl;

import com.accp.dao.ExceptionOrderDao;
import com.accp.pojo.ExceptionOrder;
import org.hibernate.HibernateException;
import org.hibernate.Query;

import java.util.ArrayList;
import java.util.List;

public class ExceptionOrderDaoImpl extends BaseDaoImpl implements ExceptionOrderDao {
	
	/**
	 * 增加异常订单
	 */
	@Override
	public boolean add(ExceptionOrder ExceptionOrder) {
		boolean flag = false;
		try{
			getSession().save(ExceptionOrder);
			flag = true;
		}catch(HibernateException e){
			e.printStackTrace();
		}
		return flag;
	}

	/**
	 * 通过ID查看信息
	 */
	@Override
	public ExceptionOrder findById(Integer id) {
		ExceptionOrder ExceptionOrder = null;
		try{
			ExceptionOrder = (ExceptionOrder) getSession().get(ExceptionOrder.class, new Integer(id));
		}catch(HibernateException e){
			e.printStackTrace();
		}
		return ExceptionOrder;
	}

	/**
	 * 删除
	 */
	@Override
	public boolean delete(ExceptionOrder ExceptionOrder) {
		boolean flag = false;
		try{
			getSession().delete(ExceptionOrder);
			flag = true;
		}catch(HibernateException e){
			e.printStackTrace();
		}
		return flag;
	}

	/**
	 * 查询MYSQL数据
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<ExceptionOrder> selectByName(String className, String patientName) {
//		Query query = this.getSession().createQuery("from "+ className + " where patientName =:patientName").setString("patientName", patientName);
		Query query = this.getSession().createQuery("from "+ className );
		return query.list();
	}
		
}
